package com.maistars.spider.service.store.console;

import com.maistars.spider.common.exception.TopicSpiderException;
import com.maistars.spider.service.store.CapturedPageStore;

import java.util.*;

/**
 * @author dhr
 * @date 2021/9/25 下午4:45
 */
public class ConsoleCapturedPageStore implements CapturedPageStore {

    private Integer taskInstId;

    private List<String> columnNames = new ArrayList<>();

    private Map<Integer,List<String>> allSuccessUrls = new HashMap<>();

    private Map<Integer,List<String>> allErrorUrls = new HashMap<>();

    public ConsoleCapturedPageStore(Integer taskInstId) {
        this.taskInstId = taskInstId;
    }

    @Override
    public void writeColumnNames() throws TopicSpiderException {
        columnNames.add("level");
        columnNames.add("url");
        System.out.println("taskInstId:" + taskInstId + " column names:" + columnNames);
    }

    @Override
    public void writeSuccessUrls(int level, List<String> urls) throws TopicSpiderException {
        allSuccessUrls.put(level,urls);
        System.out.println("level" + level + " taskInstId:" + taskInstId + " records:" + urls);
    }

    @Override
    public void writeErrorUrls(int level,List<String> urlErrorMsgs) throws TopicSpiderException {
        allErrorUrls.put(level,urlErrorMsgs);
        System.out.println("level" + level + " taskInstId:" + taskInstId + " urlErrorMsgs:" + urlErrorMsgs);
    }

    @Override
    public List<String> readColumnNames() throws TopicSpiderException {
        return columnNames;
    }

    @Override
    public Map<Integer, List<String>> readSuccessUrls() throws TopicSpiderException {
        return allSuccessUrls;
    }

    @Override
    public Map<Integer, List<String>> readErrorUrls() throws TopicSpiderException {
        return allErrorUrls;
    }
}
